package com.cn.jinl.controller;


import com.cn.jinl.api.IProcureService;
import com.cn.jinl.domain.Procure;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/procure")
public class ProcureController {

    @Autowired
    private IProcureService procureService;

    @RequestMapping("/getProcureTaskList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<Procure>> getProcureTaskList(@PathVariable(value = "frontToken",required = true) String frontToken, @RequestBody QueryForm queryForm) throws Exception{
        JsonResponse<List<Procure>> response = new JsonResponse<>();
        List<Procure> procures = procureService.getProcureTaskList(queryForm);
        response.setResult(procures);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/addProcure/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addProcure(@RequestBody Procure procure, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = procureService.addProcure(procure);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/updateCompletePayProcure/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateCompletePayProcure(Procure procure, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = procureService.updateCompletePayProcure(procure);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/updateDisProcure/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateDisProcure(Procure procure, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<>();
        String result = procureService.updateDisProcure(procure);
        return CommonUtil.getResponseData(response, result);
    }

    //获取采购任务
    @RequestMapping("/api/getAPIProcureTasks")
    @ResponseBody
    public JsonResponse<Map<String,Object>> getAPIProcureTasks(QueryForm queryForm) throws Exception{
        JsonResponse<Map<String,Object>> response = new JsonResponse<>();
        Map<String,Object> procureStorages = procureService.getAPIProcureTasks(queryForm);
        response.setResult(procureStorages);
        response.setSuccess(true);
        return response;
    }

}
